{# Approval cards (#1368): the change queue's confirmation surface, defined once and shown in the chat (a reply carries the cards its tools proposed) and in the review list. The rows are the queue's own description of the change, resolved from the database, never the model's words. Approve and Reject swap the card for its new state; Edit (a type that lets the reader put their own words on it first) opens the one dialog, and a saved edit redraws the card wherever it is up (``refresh``). #} {% from "components/macros/form.html" import action, checkbox %} {% from "components/macros/feedback.html" import error_banner %} {% from "components/macros/layout.html" import avatar, badge, facts %} {# The frame both cards share: a title line, its right-hand side as the caller's body, then ``rows``. A batch is a form so its "skip" boxes ride along: htmx sends the enclosing form's fields with a button's POST. A decided card (``decided``) folds to that line: history, not homework. ``refresh`` is how a revised card fetches itself again. #} {% macro _card(tag, id, data, title, side, by=none, decided=False, refresh="") %} {% set head %} {{ title }} {{ side }} {% endset %} <{{ tag }} id="{{ id }}" {{ data }} {{ refresh }} class="my-2 border border-aegis-border rounded-lg p-3 text-sm bg-aegis-card"> {% if decided %}
{{ head }} {% else %}
{{ head }}
{% endif %} {% if by %}
{{ by }}
{% endif %} {{ caller() }} {% if decided %}
{% endif %} {% endmacro %} {# Approve and Reject swap the card they sit on, found by its ``data`` mark: the same card can be up twice (the thread and the waiting list), so an id would find the first copy, not this one. #} {% macro _actions(url, mark, reject, edit=none) %} {% set swap = 'hx-target="closest [' ~ mark ~ ']" hx-swap="outerHTML"' %}
{{ action("Approve", 'hx-post="' ~ url ~ '/approve" ' ~ swap, tone="primary") }} {{ action(reject, 'hx-post="' ~ url ~ '/reject" ' ~ swap, tone="danger") }} {{ _edit(edit) }}
{% endmacro %} {# The reader's own words on a card first, where its type allows: the form opens in the one dialog, so every surface's card opens the same one. #} {% macro _edit(url) %}{% if url %}{{ action("Edit", hx_dialog(url, "data-edit")) }}{% endif %}{% endmacro %} {# The pictures a card carries (a scanned page, a photo), drawn from where its type says they are stored. #} {% macro _pictures(row) %} {% if row.pictures %}
{% for src in row.pictures %} Picture {{ loop.index }} of {{ loop.length }} on this card {% endfor %}
{% endif %} {% endmacro %} {# The page a card's claim was read off (``cited``), drawn where it is decided: the one moment someone could check the reading. Lazy: a queue of forty cards must not fetch forty pages to show the first screen. The intrinsic size is a rendered page's, so the box holds its place. #} {% macro _cited(cited) %} {% if cited %} {% set page %}Page {{ cited.page }}, the page this was read from{% endset %} {% set label = "Open the document at page " ~ cited.page %} {% if cited.reader %} {% else %}{{ page }}{% endif %} {% endif %} {% endmacro %} {# What a card is about: the face its service gives it, then ``caller``. #} {% macro _subject(face) %}

{% if face %}{{ avatar(**face) }}{% endif %}{{ caller() }}

{% endmacro %} {# A card's reading: its subject, the lines that will change, the page it cites or the pictures it files, and its error. #} {% macro _body(row) %} {{ _note(row) }} {% if row.subject %}{% call _subject(row.face) %}{{ row.subject }}{% endcall %}{% endif %}
{{ facts(row.display) }}
{{ _pictures(row) }} {{ _cited(row.cited) }} {% if row.error %}
{{ error_banner([row.error]) }}
{% endif %} {% endmacro %} {# Why a decided row went the way it did: a withdrawal's reason, a veto. #} {% macro _note(row) %}{% if row.note and row.status != "pending" %}

{{ row.note }}

{% endif %}{% endmacro %} {% macro change_card(change) %} {% call _card("div", "change-" ~ change.id, "data-change", change.title, badge(change.label, change.tone), change.by, decided=change.status != "pending", refresh=change.refresh) %} {{ _body(change) }} {% if change.status == "pending" %}{{ _actions(change.url, "data-change", "Reject", change.edit) }}{% endif %} {% endcall %} {% endmacro %} {# One row of a batch: its skip while it waits, its outcome after. #} {% macro _batch_row(row) %}
  • {% if row.status == "pending" %}{{ checkbox("exclude_ids", label="Skip this one", value=row.id) }}{% endif %} {{ _edit(row.edit) }}{{ badge(row.label, row.tone) }}
    {{ _body(row) }}
  • {% endmacro %} {# A batch: every row with its own skip, rows that say the same thing (``groups``) read once - what they share, how many, what they come to and over what span - with one skip for all of them (app.js ticks the rows' own boxes, which are all the form reads) and the rows behind a fold: what folds is the reading, never the control. #} {% macro batch_card(batch) %} {% set count = batch.rows|length %} {% set side = count ~ (" change" if count == 1 else " changes") if batch.pending else batch.outcome %} {% call _card("form", "batch-" ~ batch.batch_id, "data-change-batch", batch.title, side, batch.by, decided=not batch.pending, refresh=batch.refresh) %} {% if batch.pending %}{{ _actions(batch.url, "data-change-batch", "Reject all") }}{% endif %} {% endcall %} {% endmacro %} {# Redraws ``target`` from ``url`` when a card is decided anywhere on the page (``change_resolved``, from the card routes), so what was approved shows on the page behind at once. An element of its OWN, hidden and childless: put on the section itself, its hx-select and hx-target are inherited by the lazy blocks inside it. ``include`` carries a form's fields along (a list's filters). #} {% macro redraws_on_decision(url, target, include=None) -%} {%- endmacro %}